package com.feng.zhihao.apigeteway.gateway.bean.impl.INTERFACE_FIELD_POSITION.REQ;

import org.springframework.stereotype.Component;

import com.feng.zhihao.apigeteway.entity.InterfaceFieldInfo;
import com.feng.zhihao.apigeteway.exception.ExceptionMessage;
import com.feng.zhihao.apigeteway.exception.GetewayException;
import com.feng.zhihao.apigeteway.gateway.ReqContext;
import com.feng.zhihao.apigeteway.gateway.bean.INTERFACE_FIELD_POSITION_REQ;
import com.feng.zhihao.apigeteway.util.ParamsUtil;

import ognl.Ognl;
import ognl.OgnlException;

@Component("FIELD_POSITION_REQ_PARAMS")
public class FIELD_POSITION_REQ_PARAMS implements INTERFACE_FIELD_POSITION_REQ {

	@Override
	public Object getValue(InterfaceFieldInfo interfaceFieldInfo, ReqContext reqContext) {
		if(reqContext.getReqParams() == null){
			return null;
		}
		String path=ParamsUtil.getPath(interfaceFieldInfo);
		try {
			return Ognl.getValue(path, reqContext);
		} catch (OgnlException e) {
			throw new GetewayException(e,ExceptionMessage.PARAMS_OGNL_EXCEPTION,interfaceFieldInfo.getInterfaceFieldName(),path);
		}
	}

}
